home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / RCS / realloc.c,v < prev    next >
Encoding:
Text File  |  1989-12-19  |  2.2 KB  |  107 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     88.07.29.17.04.22;  author ouster;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     88.05.20.15.49.31;  author ouster;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @Lint.
  27. @
  28. text
  29. @/* 
  30.  * realloc.c --
  31.  *
  32.  *    Source code for the "realloc" library procedure.
  33.  *
  34.  * Copyright 1988 Regents of the University of California
  35.  * Permission to use, copy, modify, and distribute this
  36.  * software and its documentation for any purpose and without
  37.  * fee is hereby granted, provided that the above copyright
  38.  * notice appear in all copies.  The University of California
  39.  * makes no representations about the suitability of this
  40.  * software for any purpose.  It is provided "as is" without
  41.  * express or implied warranty.
  42.  */
  43.  
  44. #ifndef lint
  45. static char rcsid[] = "$Header: realloc.c,v 1.1 88/05/20 15:49:31 ouster Exp $ SPRITE (Berkeley)";
  46. #endif not lint
  47.  
  48. #include <bstring.h>
  49. #include "stdlib.h"
  50.  
  51. /*
  52.  *----------------------------------------------------------------------
  53.  *
  54.  * realloc --
  55.  *
  56.  *    Change the size of the block referenced by ptr to "size",
  57.  *    possibly moving the block to a larger storage area.
  58.  *
  59.  * Results:
  60.  *    The return value is a pointer to the new area of memory.
  61.  *    The contents of this block will be unchanged up to the
  62.  *    lesserof the new and old sizes.
  63.  *
  64.  * Side effects:
  65.  *    The old block of memory may be released.
  66.  *
  67.  *----------------------------------------------------------------------
  68.  */
  69.  
  70. char *
  71. realloc(ptr, newSize)
  72.     char      *ptr;        /* Ptr to currently allocated block.  If
  73.                  * it's 0, then this procedure behaves
  74.                  * identically to malloc. */
  75.     unsigned int newSize;    /* Size of block after it is extended */
  76. {
  77.     unsigned int curSize;
  78.     char *newPtr;
  79.  
  80.     if (ptr == 0) {
  81.     return malloc(newSize);
  82.     }
  83.     curSize = Mem_Size(ptr);
  84.     if (newSize <= curSize) {
  85.     return ptr;
  86.     }
  87.     newPtr = malloc(newSize);
  88.     bcopy(ptr, newPtr, (int) curSize);
  89.     free(ptr);
  90.     return(newPtr);
  91. }
  92. @
  93.  
  94.  
  95. 1.1
  96. log
  97. @Initial revision
  98. @
  99. text
  100. @d17 1
  101. a17 1
  102. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  103. d60 1
  104. a60 1
  105.     bcopy(ptr, newPtr, curSize);
  106. @
  107.